<?php
class User_feed_back_model extends CI_Model
{
    private $table   = 'user_feedback';
    private $table_2 = 'user';
    /**
     * 符合搜索条件数据的总数量
     */
    public function total($search_param=array())
    {
        if (!empty($search_param['type'])) {
            $this->db->where('type', $search_param['type']);
        }
        if (!empty($search_param['mobile'])) {
            $this->db->like('mobile', $search_param['mobile']);
        }
        if (!empty($search_param['email'])) {
            $this->db->like('email', $search_param['email']);
        }
        if (!empty($search_param['start_date'])) {
            $this->db->where(array('create_time >=' => $search_param['start_date'].' 00:00:00'));
        }
        if (!empty($search_param['end_date'])) {
            $this->db->where(array('create_time <=' => $search_param['end_date'].' 23:59:59'));
        }
        return $this->db->count_all_results($this->table);
    }
    
    /**
     *符合搜索条件数据 默认取20条
     */
    public function page_list($page_num, $num, $search_param=array())
    {
        $this->db->select('a.*,b.alias_name');
        $this->db->from($this->table.' as a');
        $this->db->join($this->table_2.' as b','a.uid = b.uid');
        if (!empty($search_param['type'])) {
            $this->db->where('a.type', $search_param['type']);
        }
        if (!empty($search_param['mobile'])) {
            $this->db->like('a.mobile', $search_param['mobile']);
        }
        if (!empty($search_param['email'])) {
            $this->db->like('a.email', $search_param['email']);
        }
        if (!empty($search_param['start_date'])) {
            $this->db->where(array('a.create_time >=' => $search_param['start_date'].' 00:00:00'));
        }
        if (!empty($search_param['end_date'])) {
            $this->db->where(array('a.create_time <=' => $search_param['end_date'].' 23:59:59'));
        }
        $this->db->order_by('a.create_time','desc');
        $this->db->limit($page_num, $num);
        return $this->db->get();
    }
}